package com.imay.live.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.imay.cocos.IMayCocos;
import com.imay.cocos.IMayCocosNetManager;
import com.imay.live.R;
import com.imay.tsnackbar.ScreenUtil;

public class MarketActivity extends BaseCocosActivity implements IMayCocosNetManager.OnCocosShopListener {
    IMayCocos.OnCocosUpdateListener onCocosUpdateListener;
    private static final String TAG_MOUNTID = "TAG_MOUNTID";
    //默认选中的坐骑id
    private int mountId;

    public static void start(Context context,int mountId) {
        Intent starter = new Intent(context, MarketActivity.class);
        starter.putExtra(TAG_MOUNTID,mountId);
        starter.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(starter);
    }

    private FrameLayout fl_container_market;

    @Override
    protected int getLayoutId() {
//        requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        return R.layout.activity_market;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        fl_container_market = $(R.id.fl_container_market);
        mountId = getIntent().getIntExtra(TAG_MOUNTID,0);
        showCocosView();
//        ScreenUtil.fullScreen(this,true);
    }

    @Override
    protected boolean isSetDecorViewBackground() {
        return false;
    }

    private void showCocosView() {
        addCocosView(fl_container_market);
        if (onCocosUpdateListener==null){
            onCocosUpdateListener = new IMayCocos.OnCocosUpdateListener() {
                @Override
                public void onCocosAllowAction(int state) {
                    if (state == 3) {
                        IMayCocos.showMarketPanel(mountId==0?null:mountId);
                    }
                }
            };
        }
        IMayCocos.getInstance().addOnCocosUpdateListener(onCocosUpdateListener);
        IMayCocosNetManager.getInstance().setOnCocosShopListener(this);
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        IMayCocos.closeMarketPannel();

    }

    @Override
    protected void onDestroy() {
        IMayCocos.closeMarketPannel();
        IMayCocosNetManager.getInstance().removeOnCocosRoomHouseListener();
        IMayCocos.getInstance().removeOnCocosUpdateListener(onCocosUpdateListener);
        super.onDestroy();
    }

    @Override
    protected void onCocosViewAddAgain() {
        IMayCocos.showMarketPanel(mountId==0?null:mountId);
        super.onCocosViewAddAgain();
    }

    @Override
    protected boolean useDynamicTitleBar() {
        return false;
    }

    @Override
    public void onCloseShopUI() {
        finish();
    }

    @Override
    public void onCocosRechargeClick() {

    }
}
